Typically, a computer system contains a processor, a bus, and other peripheral units. The processor is responsible for executing instructions using the data in the computer system. The bus is used by the processor and the peripheral devices for transferring information between one and another. The information on the bus usually includes data, address and control signals. The peripheral devices compose storage devices, input/output (I/O) devices, etc.
The processor in the computer system usually includes one or more numeric processing units for performing numeric operations specified by instructions received by the processor. These instructions specify operands (e.g., numbers) on which a particular mathematical operation is performed. The number of operands specified is dependent on the operation being performed, with the majority of operations requiring one or two operands.
One of the numeric operations often performed by a processing unit is a transcendental. Transcendentals are time-consuming calculations for common trigonometric, inverse trigonometric, hyperbolic, inverse hyperbolic, logarithmic and exponential functions. These functions typically cannot be calculated precisely. Therefore, approximations are used for these functions. These approximations often require many intermediate numeric calculations.
The intermediate and (pre-rounded) final results of performing numeric operations may have to be rounded. Rounding an operand refers to the deletion of one or more of the least significant digits of the operand and may include the adjustment of the remaining portion of the operand in accordance with some specified rule. Once it is determined that a number needs to be rounded, a rounding method must be selected. Some of the more common rounding methods include: truncation, round toward positive infinity, round toward negative infinity and round to nearest/even. Truncation, referred to as "chop" or "round toward zero", corresponds to deleting a portion of the least significant bits, thus producing a value smaller in magnitude (i.e., closer to zero) than the unrounded value. Rounding toward positive infinity implies increasing the operand's magnitude if the operand is positive or decreasing the operand's magnitude if its magnitude is negative. Rounding toward negative infinity implies decreasing the operand's magnitude if the operand is positive or increasing the operand if the magnitude of the operand is negative.
One purpose for rounding is to reduce the number of digits in the operand so that the rounded operand can fit within the word size of the processing unit. In floating point operands, a notation is used in which the operand is characterized as a characteristic and a mantissa. The characteristic reference represents the integral value of the number, and the mantissa represents the decimal value of the number. For example, if the number 6.3124 is comprised of a characteristic of 6 and a mantissa of 3124. With respect to floating point operations, there are many situations in which the result of a floating point operation exceeds the processing units word size. For example, the addition of two n-bit numbers might result in a sum of n+1 bits. Consequently, an overflow results if the word size is only n-bits long. To fit the result into the word size, the number may be shifted one position to the right, the least significant bit (LSB) deleted and the exponent increased. In order to dispose of the LSB while still preserving accurate results, the number is rounded according to one of several rounding methods.
Another reason for rounding is to scale the mantissa to certain precisions. The longer the mantissa length, the more precise it becomes. However, calculations using operands with longer mantissas require more time because more bits are being manipulated. Commonly, precisions are adapted according to the specification set forth in the Institute of Electrical and Electronic Engineers (IEEE) standard 754. The standard specifies four precisions: single, single-extended, double and double-extended. Implementations are not required to have all four precisions.
By way of illustration, single precision is 24-bits in length. Double precision consists of 53-bits and extended precision consists of 64-bits. Thus, if the user selects single precision, every bit trailing LSB "43"(bits 42-0 of a 68-bit number) is deleted and set to "0". The LSB is rounded depending upon the rounding method chosen. Likewise, if the user selects double precision, the LSB "14"and trailing bits "13-0"are set to zero. The appropriate rounding is then implemented. The same procedure occurs if extended precision is selected. The only difference is that LSB is bit "3"and bits "2-0"are set zero. Again, the appropriate rounding is performed.
Rounding is often utilized in performing the numeric calculations associated with transcendentals or other complex calculations that require multiple subcalculations. Because the transcendentals involve multiple calculations, the use of rounding may occur at numerous times when arriving at a result. It is a valuable characteristic for an approximation of a transcendental to be monatomic. Monotonicity indicates that an approximation represents an "ever increasing" or "ever decreasing" function with respect to infinite mathematics. The indiscriminate use of rounding at multiple times during the calculation of a transcendental can cause an approximation to not be monatomic. Therefore, it is desirable to calculate transcendentals and other complex numeric operations that require multiple subcalculations in such a manner as to maintain their monotonicity.
The present invention provides a method and apparatus for rounding operands. The present invention also rounds operands such that their monotonicity is maintained.